package pv.finder.search;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import pv.dao.table.PlaceTable;
import pv.dto.DistrictDTO;
import pv.util.DataSearch;

public class DistrictSearch extends ProvinceSearch {
	protected DistrictDTO district;

	public DistrictDTO getDistrict() {
		return district;
	}

	public void setDistrict(DistrictDTO district) {
		this.district = district;
	}

	@Override
	public String getWhereColumn() {
		// TODO Auto-generated method stub
		String whereColum = super.getWhereColumn();

		if (whereColum != null && district != null) {
			return whereColum + " AND " + PlaceTable.DISTRICT_ID + " LIKE ?";
		} else {
			return whereColum != null ? whereColum
					: (district != null ? (PlaceTable.DISTRICT_ID + " LIKE ?")
							: null);
		}

	}

	@Override
	public String[] getWhereValue() {
		// TODO Auto-generated method stub
		String[] arrayItems = super.getWhereValue();
		List<String> list = new ArrayList<String>();
		if (arrayItems != null && arrayItems.length != 0)
			list = Arrays.asList(arrayItems);
		if (district != null)
			list.add(String.valueOf(district.getId()));

		if (list.isEmpty())
			return null;
		else
			return list.toArray(new String[list.size()]);
	}

}
